# coding:utf-8
import pymongo
from bson import ObjectId
from gridfs import GridFS
from snownlp import SnowNLP

from app import db

tbArticle = db["article"]


# 文章情感分析
# {keywords:[],sentiment:{dictPos:10,dictNeg:20,beiyesPos:10,beiyesNeg:20}}
# pos:为积极句子个数
# keywords:为关键词

def addSentiment(id, keywords, sentiment, wordFreq):
    query = {"_id": ObjectId(id)}
    newvalues = {"$set": {"keywords": keywords,
                          "sentiment": sentiment,
                          "wordFreq":wordFreq}}
    tbArticle.update_one(query, newvalues)


if __name__ == '__main__':
    keywords = [
        "person",
        "我们",
        "学校"
    ]
    sentiment = {'pos':10,'neg':20}
    addSentiment('5cd2bebd3e766209f486a25b', keywords, sentiment)
    s = SnowNLP('nllll')
    print(s.sentiments)

